package com.example.demo.repository;

import com.example.demo.pojo.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserRepository extends JpaRepository<User, Integer> {

    @Query(value = "select count(*) from user where is_delete = false", nativeQuery = true)
    Integer countAll();

    @Query(value = "select * from user where u_name = ? and is_delete = false", nativeQuery = true)
    User findUserByU_name(String name);

    @Query(value = "select * from user where u_id = ? and is_delete = false", nativeQuery = true)
    User findUserByU_id(Integer id);

    @Query(value = "select * from user where is_delete = false limit ?1, ?2", nativeQuery = true)
    List<User> findByPage(int start, int listNum);

    @Modifying
    @Query(value = "update user set is_delete = ?2 where u_id = ?1", nativeQuery = true)
    void deleteUser(Integer id, boolean result);
}
